﻿<%@ codepage=65001%><% 'UTF-8%>

<% '商品管理%>
<!--#include file="../Include/Common.All.asp"-->
<!--#include file="../Include/Conn.asp"-->
<% call OpenConn%>

<!--#include file="../Include/Common.Security.asp"-->
<!--#include file="../Include/MD5.asp"-->
<!--#include file="../Include/JSON_2.0.2.asp"-->
<!--#include file="../Include/JSON_UTIL_0.1.1.asp"-->



<%

	'定义json对象
	Dim jsonObj,jsonObj_user
	Set jsonObj = jsObject()
	Set jsonObj_user = jsObject()
	UserID=ReplaceBadChar(Trim(Session("UserID")))
	
	dim act 
  act=request("act")
 	Dim rsObj,strSql
 	''定义查询字段变量
 	dim id, spcode, spname, sccs, gg, shangbiao 
	''查询信息列表
	if "search"=act then
		spcode=ReplaceBadChar(Trim(request.Form("spcode")))
		spname=ReplaceBadChar(Trim(request.Form("spname")))
				
		jsonObj("rslist") = ""
		''添加用户信息
		jsonObj_user("UserID") = UserID 
		jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
		Set jsonObj("customer") = jsonObj_user 
	 
		''添加查询结果信息
		''Dim rsObj,strSql
		strSql = "SELECT id, spcode, spname, sccs, gg, shangbiao  FROM SP_XX "   & "WHERE 1=1 "
		If (spcode <> "") Then strSql=strSql & " and spcode like '%" & spcode & "%'  "
		If (spname <> "") Then strSql=strSql & " and spname like '%" & spname & "%'  "
		Set jsonObj("rslist") = QueryToJSON(Conn, strSql)
		
 elseif "add"=act then
 			jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..."'''' "操作失败，请重试..."
			jsonObj("success") = 0'"false"

''添加信息

			id=ReplaceBadChar(Trim(request.Form("id")))
			spcode=ReplaceBadChar(Trim(request.Form("spcode")))
			spname=ReplaceBadChar(Trim(request.Form("spname")))
			sccs=ReplaceBadChar(Trim(request.Form("sccs")))
			gg=ReplaceBadChar(Trim(request.Form("gg")))
			shangbiao=ReplaceBadChar(Trim(request.Form("shangbiao")))			
 
 
			''Dim rsObj,strSql
			set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from SP_XX where spcode='"&spcode&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				rsObj.AddNew '如果没记录新增，有记录update	
				strSql = "select ISNULL(MAX(id), 0)  from SP_XX  "
				id = PE_CLng(Conn.Execute(strSql)(0)) + 1
			end if				
			rsObj("id") = id
			rsObj("spcode") = spcode
			rsObj("spname") = spname
			rsObj("sccs") = sccs
			rsObj("gg") = gg
			rsObj("shangbiao") = shangbiao
			rsObj.Update
			rsObj.close
			Set rsObj = Nothing
		 
			jsonObj("msg") = "&#x6DFB;&#x52A0;&#x6210;&#x529F;&#xFF0C;&#x6B63;&#x5728;&#x8DF3;&#x8F6C;..." ''' "添加成功，正在跳转..."
			jsonObj("success") = 1'"success"
			jsonObj("url") = "product.asp"
	 	 		
 elseif "edit"=act then
 			jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..." '''"操作失败，请重试..."
			jsonObj("success") = 0'"false"
			
 
''修改信息

			id=ReplaceBadChar(Trim(request.Form("pid")))
			spcode=ReplaceBadChar(Trim(request.Form("spcode")))
			spname=ReplaceBadChar(Trim(request.Form("spname")))
			sccs=ReplaceBadChar(Trim(request.Form("sccs")))
			gg=ReplaceBadChar(Trim(request.Form("gg")))
			shangbiao=ReplaceBadChar(Trim(request.Form("shangbiao")))			
 
 
			''Dim rsObj,strSql
			set rsObj=Server.CreateObject("ADODB.Recordset")
			strSql = "Select  * from SP_XX where id='"&id&"' "
			''Response.Write strSql&"-----"
			rsObj.Open strSql, Conn, 1, 3
			If rsObj.BOF And rsObj.EOF Then 
				jsonObj("msg") = "&#x64CD;&#x4F5C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x91CD;&#x8BD5;..." ''' "操作失败，请重试..."
				jsonObj("success") = 0'"false"
			else				
				rsObj("id") = id
				rsObj("spcode") = spcode
				rsObj("spname") = spname
				rsObj("sccs") = sccs
				rsObj("gg") = gg
				rsObj("shangbiao") = shangbiao
				rsObj.Update
			 
				jsonObj("msg") = "&#x6DFB;&#x52A0;&#x6210;&#x529F;&#xFF0C;&#x6B63;&#x5728;&#x8DF3;&#x8F6C;..."'' "添加成功，正在跳转..."
				jsonObj("success") = 1'"success"
				jsonObj("url") = "product.asp"
	 		end if	
			rsObj.close
			Set rsObj = Nothing
 
 elseif "delete"=act then
''删除记录
		id=ReplaceBadChar(Trim(request.Form("id"))) 
    Dim  RowCount 
    RowCount = 0
    If (id <> "" ) Then 
    	Conn.Execute ("delete from SP_XX where id='"&id&"'"), RowCount
    End If
    If RowCount = 0 Then
        jsonObj("success") = 0 'false
        jsonObj("msg") = "&#x8BB0;&#x5F55;&#x5220;&#x9664;&#x5931;&#x8D25;&#x3002;" '''' "记录删除失败。" 
    Else
        jsonObj("msg") = 	"&#x5220;&#x9664;&#x6210;&#x529F;&#xFF0C;&#x6B63;&#x5728;&#x8DF3;&#x8F6C;..." ''''"删除成功，正在跳转..." 
				jsonObj("success") = 1'"success"
				jsonObj("url") = "product.asp"
    End If
  

	end If''''删除记录
 

	'输出json对象
	jsonObj.Flush
	''Response.Write strSql&"-----"
 '释放数据库链接
	call CloseConn

''{
''    rslist : [ { name: "mac", desc: "computer",     
''                   price: 1000, quantity: 100, alert:null },
''                 { name: "ipod", desc: "music player", 
''                   price:  200, quantity: 200, alert:"on sale now!" },
''                 { name: "cinema display", desc: "screen",       
''                   price:  800, quantity: 300, alert:"best deal!" } ],
''    customer : { first: "John", last: "Public", level: "gold" }
''}

%>